package common

import "git.oschina.net/zhgk/goutil"


//创建一个对象，用于接收客户端发送的JSON数据请求，请求格式为：application/json
type ReqJsonData map[string]interface{}
//根据Key 获取值
func (rj ReqJsonData)Get(key string) (value interface{}, exist bool) {
	val, ok := rj[key]
	return val, ok
}
//根据Key获取值，并指定默认值
func (rj ReqJsonData)GetDefault(key string, def interface{}) (interface{}) {
	if val, ok := rj[key]; ok {
		return val
	}
	return def
}
//根据Key获取String类型的值
//返回【值：是否存在】
func (rj ReqJsonData)GetString(key string) (string, bool) {
	if val, ok := rj[key]; ok {
		return goutil.ToString(val), true
	}
	return "", false
}

//根据Key获取类型为字符符串的Value,设置默认值
func (rj ReqJsonData)GetDefaultString(key, def string) string {
	if val, ok := rj[key]; ok {
		return goutil.ToString(val)
	}
	return def
}

//插入键值
func (rj ReqJsonData)Put(key string, value interface{}) {
	rj[key] = value
}
//删除键值
func (rj ReqJsonData)Remove(key string) {
	delete(rj, key)
}
//弹出键值
func (rj ReqJsonData)Pop(key string) interface{} {
	value := rj.GetDefault(key, nil)
	rj.Remove(key)
	return value
}

const SUCCESS string = "SUCCESS"
